// 完成思路 。在本地里面存一个点击过的列表clickitem.
// 把每个点击的东西都加进去，在wxml里面搞一个wxs来判定。

Page({
  data: {
    option1: [{
      text: '跟团游',
      value: 0
    },
    
    {
      text: '选择定制',
      value: 2
    },
  ],
value1: 2,
    placeList: [],
    clickitem:[],
    placelist:wx.getStorageSync('placelist'),
    pricelist:wx.getStorageSync('pricelist'),
    itemlist:wx.getStorageSync('itemlist'),
    activeNames: ['1'],
  },
  removeByValue(arr, val) {
    for (let i = 0; i < arr.length; i++) {
      if (arr[i] === val) {
        arr.splice(i, 1);
        this.setData({
          clickitem:arr
        })
        wx.setStorageSync('clickitem', arr)
        break;
      }
    }
  },
  option1change(e){
    console.log(e)
    var index=e.detail
    if (index==0) {
      // 选择了 定制
      wx.reLaunch({
        url: '../tuanjian/tuanjian',
      })
    }
  },
  cancle(e){
    console.log(e)
    var index=e.currentTarget.dataset.index
    wx.showModal({
      title: '提示',
      content: '是否取消该选择',
      complete: (res) => {
        if (res.cancel) {
          
        }
    
        if (res.confirm) {
          //删除this.data.clickitem就可以
          var clickitem=this.data.clickitem
          this.removeByValue(clickitem,index)
        }
      }
    })
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  todingzhipay(e){
    wx.navigateTo({
      url: '../tjdingzhipay/tjdingzhipay',
    })
  },
  clickit(e){
    console.log(e)
    var index=e.currentTarget.dataset.index
    wx.showModal({
      title: '提示',
      content: '是否选择',
      complete: (res) => {
        if (res.cancel) {
          
        }
    
        if (res.confirm) {
          var clickitem=this.data.clickitem
          
          if (clickitem.length==0) {
            clickitem=[]
          }
          clickitem.push(index)
          this.setData({
            clickitem
          })
          wx.setStorageSync('clickitem', clickitem)
        }
      }
    })
  },
  onLoad() {
    this.getplace()
  },
  onShow(){
    var clickitem=wx.getStorageSync('clickitem')
    this.setData({
      clickitem
    })
  },
  getplace() {
    wx.showLoading({
      title: '正在加载',
    })
    wx.cloud.callFunction({
      name: 'getallplacelist'
    }).then(res => {
      console.log(res)
      this.setData({
        placeList: res.result.data.reverse()
      })
      wx.hideLoading()
    })
  },
})